home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / address.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  8KB  |  219 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import time
  5. import urlparse
  6. import socket
  7. from ZSI import _seqtypes, EvaluateException, WSActionException
  8. from TC import AnyElement, AnyType, TypeCode
  9. from schema import GED, GTD, _has_type_definition
  10. from ZSI.TCcompound import ComplexType
  11. from ZSI.wstools.Namespaces import WSA_LIST
  12.  
  13. class Address(object):
  14.     
  15.     def __init__(self, addressTo = None, wsAddressURI = None, action = None):
  16.         self.wsAddressURI = wsAddressURI
  17.         self.anonymousURI = None
  18.         self._addressTo = addressTo
  19.         self._messageID = None
  20.         self._action = action
  21.         self._endPointReference = None
  22.         self._replyTo = None
  23.         self._relatesTo = None
  24.         self.setUp()
  25.  
  26.     
  27.     def setUp(self):
  28.         toplist = (filter,)((lambda wsa: wsa.ADDRESS == self.wsAddressURI), WSA_LIST)
  29.         epr = 'EndpointReferenceType'
  30.         for WSA in toplist + WSA_LIST:
  31.             if self.wsAddressURI is not None or self.wsAddressURI != WSA.ADDRESS or _has_type_definition(WSA.ADDRESS, epr) is True:
  32.                 break
  33.                 continue
  34.         else:
  35.             raise EvaluateException, 'enabling wsAddressing requires the inclusion of that namespace'
  36.         self.wsAddressURI = WSA.ADDRESS
  37.         self.anonymousURI = WSA.ANONYMOUS
  38.         self._replyTo = WSA.ANONYMOUS
  39.  
  40.     
  41.     def _checkAction(self, action, value):
  42.         if action is None:
  43.             raise WSActionException, 'Response missing WSAddress Action'
  44.         
  45.         if not value:
  46.             raise WSActionException, 'missing WSAddress Action, expecting %s' % action
  47.         
  48.         if value != action:
  49.             raise WSActionException, 'wrong WSAddress Action(%s), expecting %s' % (value, action)
  50.         
  51.  
  52.     
  53.     def _checkFrom(self, pyobj):
  54.         if pyobj is None:
  55.             return None
  56.         
  57.         value = pyobj._Address
  58.         if value != self._addressTo:
  59.             (scheme, netloc, path, query, fragment) = urlparse.urlsplit(value)
  60.             hostport = netloc.split(':')
  61.             (schemeF, netlocF, pathF, queryF, fragmentF) = urlparse.urlsplit(self._addressTo)
  62.             if scheme == schemeF and path == pathF and query == queryF and fragment == fragmentF:
  63.                 netloc = netloc.split(':') + [
  64.                     '80']
  65.                 netlocF = netlocF.split(':') + [
  66.                     '80']
  67.                 if netloc[1] == netlocF[1] and socket.gethostbyname(netlocF[0]) in ('127.0.0.1', socket.gethostbyname(netloc[0])):
  68.                     return None
  69.                 
  70.             
  71.             raise WSActionException, 'wrong WS-Address From(%s), expecting %s' % (value, self._addressTo)
  72.         
  73.  
  74.     
  75.     def _checkRelatesTo(self, value):
  76.         if value != self._messageID:
  77.             raise WSActionException, 'wrong WS-Address RelatesTo(%s), expecting %s' % (value, self._messageID)
  78.         
  79.  
  80.     
  81.     def _checkReplyTo(self, value):
  82.         if value != self._replyTo:
  83.             raise WSActionException, 'wrong WS-Address ReplyTo(%s), expecting %s' % (value, self._replyTo)
  84.         
  85.  
  86.     
  87.     def setAction(self, action):
  88.         self._action = action
  89.  
  90.     
  91.     def getAction(self):
  92.         return self._action
  93.  
  94.     
  95.     def getRelatesTo(self):
  96.         return self._relatesTo
  97.  
  98.     
  99.     def getMessageID(self):
  100.         return self._messageID
  101.  
  102.     
  103.     def _getWSAddressTypeCodes(self, **kw):
  104.         typecodes = []
  105.         
  106.         try:
  107.             for nsuri, elements in kw.items():
  108.                 for el in elements:
  109.                     typecode = GED(nsuri, el)
  110.                     if typecode is None:
  111.                         raise WSActionException, 'Missing namespace, import "%s"' % nsuri
  112.                     
  113.                     typecodes.append(typecode)
  114.                 
  115.         except EvaluateException:
  116.             ex = None
  117.             raise EvaluateException, 'To use ws-addressing register typecodes for namespace(%s)' % self.wsAddressURI
  118.  
  119.         return typecodes
  120.  
  121.     
  122.     def checkResponse(self, ps, action):
  123.         namespaceURI = self.wsAddressURI
  124.         d = {
  125.             namespaceURI: ('MessageID', 'Action', 'To', 'From', 'RelatesTo') }
  126.         typecodes = self._getWSAddressTypeCodes(**d)
  127.         pyobjs = ps.ParseHeaderElements(typecodes)
  128.         got_action = pyobjs.get((namespaceURI, 'Action'))
  129.         self._checkAction(action, got_action)
  130.         From = pyobjs.get((namespaceURI, 'From'))
  131.         self._checkFrom(From)
  132.         RelatesTo = pyobjs.get((namespaceURI, 'RelatesTo'))
  133.         self._checkRelatesTo(RelatesTo)
  134.         To = pyobjs.get((namespaceURI, 'To'))
  135.         if To:
  136.             self._checkReplyTo(To)
  137.         
  138.  
  139.     
  140.     def setRequest(self, endPointReference, action):
  141.         self._action = action
  142.         self.header_pyobjs = None
  143.         pyobjs = []
  144.         namespaceURI = self.wsAddressURI
  145.         addressTo = self._addressTo
  146.         messageID = self._messageID = 'uuid:%s' % time.time()
  147.         typecode = GED(namespaceURI, 'MessageID')
  148.         pyobjs.append(typecode.pyclass(messageID))
  149.         typecode = GED(namespaceURI, 'Action')
  150.         pyobjs.append(typecode.pyclass(action))
  151.         typecode = GED(namespaceURI, 'To')
  152.         pyobjs.append(typecode.pyclass(addressTo))
  153.         typecode = GED(namespaceURI, 'From')
  154.         mihFrom = typecode.pyclass()
  155.         mihFrom._Address = self.anonymousURI
  156.         pyobjs.append(mihFrom)
  157.         if endPointReference:
  158.             if hasattr(endPointReference, 'typecode') is False:
  159.                 raise EvaluateException, 'endPointReference must have a typecode attribute'
  160.             
  161.             if isinstance(endPointReference.typecode, GTD(namespaceURI, 'EndpointReferenceType')) is False:
  162.                 raise EvaluateException, 'endPointReference must be of type %s' % GTD(namespaceURI, 'EndpointReferenceType')
  163.             
  164.             ReferenceProperties = getattr(endPointReference, '_ReferenceProperties', None)
  165.             if ReferenceProperties is not None:
  166.                 for v in getattr(ReferenceProperties, '_any', ()):
  167.                     if not hasattr(v, 'typecode'):
  168.                         raise EvaluateException, '<any> element, instance missing typecode attribute'
  169.                     
  170.                     pyobjs.append(v)
  171.                 
  172.             
  173.         
  174.         self.header_pyobjs = tuple(pyobjs)
  175.  
  176.     
  177.     def setResponseFromWSAddress(self, address, localURL):
  178.         self.From = localURL
  179.         self.header_pyobjs = None
  180.         pyobjs = []
  181.         namespaceURI = self.wsAddressURI
  182.         for nsuri, name, value in ((namespaceURI, 'Action', self._action), (namespaceURI, 'MessageID', 'uuid:%s' % time.time()), (namespaceURI, 'RelatesTo', address.getMessageID()), (namespaceURI, 'To', self.anonymousURI)):
  183.             typecode = GED(nsuri, name)
  184.             pyobjs.append(typecode.pyclass(value))
  185.         
  186.         typecode = GED(nsuri, 'From')
  187.         pyobj = typecode.pyclass()
  188.         pyobj._Address = self.From
  189.         pyobjs.append(pyobj)
  190.         self.header_pyobjs = tuple(pyobjs)
  191.  
  192.     
  193.     def serialize(self, sw, **kw):
  194.         for pyobj in self.header_pyobjs:
  195.             if hasattr(pyobj, 'typecode') is False:
  196.                 raise RuntimeError, 'all header pyobjs must have a typecode attribute'
  197.             
  198.             sw.serialize_header(pyobj, **kw)
  199.         
  200.  
  201.     
  202.     def parse(self, ps, **kw):
  203.         namespaceURI = self.wsAddressURI
  204.         elements = ('MessageID', 'Action', 'To', 'From', 'RelatesTo')
  205.         d = {
  206.             namespaceURI: elements }
  207.         typecodes = self._getWSAddressTypeCodes(**d)
  208.         pyobjs = ps.ParseHeaderElements(typecodes)
  209.         self._messageID = pyobjs[(namespaceURI, elements[0])]
  210.         self._action = pyobjs[(namespaceURI, elements[1])]
  211.         self._addressTo = pyobjs[(namespaceURI, elements[2])]
  212.         self._from = pyobjs[(namespaceURI, elements[3])]
  213.         self._relatesTo = pyobjs[(namespaceURI, elements[4])]
  214.  
  215.  
  216. if __name__ == '__main__':
  217.     print _copyright
  218.  
  219.